package com.yequan.leetcode.linkedlist.swappairs_24;

import com.yequan.leetcode.linkedlist.ListNode;

/**
 * @author yequan
 * @date 2021/10/31 20:16
 **/
public class RecodeSwapPairs {

    public ListNode swapPairs(ListNode head) {
        if (null == head || head.next == null) {
            return head;
        }
        ListNode preHead = new ListNode(-1);
        preHead.next = head;
        ListNode tempNode = preHead;
        while (tempNode.next != null && tempNode.next.next != null) {
            ListNode node1 = tempNode.next;
            ListNode node2 = tempNode.next.next;
            tempNode.next = node2;
            node1.next = node2.next;
            node2.next = node1;
            tempNode = node1;
        }
        return preHead.next;
    }

}
